<template>
  <div id="bacBreakPoint">
    <Breadcrumb content="自定义折点" />
    <div class="bodyContent">
      <!-- vxe-toolbar -->
      <Splitpanes class="area">
        <Pane size="30">
          <el-container style="height: 100%">
            <el-aside width="80px" class="bg-white padding-xs" style="background-color: #fff !important; cursor: pointer">
              <div style="max-width: 78px" class="margin-xs light padding-xs radius text-center" :class="m.isactive == 'true' ? 'bg-green' : 'bg-grey'" :key="i" v-for="(m, i) in groupCategory" @click="changeGroupCategory(m.value)">
                <p class="text item">{{ `${m.label}` }}</p>
              </div>
            </el-aside>
            <el-main>
              <Splitpanes>
                <Pane size="40">
                  <vxe-toolbar class="bg-olive light solid line-bottom text-orange" class-name="bg-olive light solid line-bottom text-orange">
                    <template #buttons>
                      <span class="margin-right-xs text-bold margin-left-xs">类别明细值</span>
                    </template>
                  </vxe-toolbar>
                  <vxe-toolbar perfect>
                    <template #buttons>
                      <span class="margin-right-xs text-bold">条件值</span>
                      <vxe-select v-model="filterCondition.filterCondition" placeholder="条件" style="width: calc(100% - 55px)">
                        <vxe-option :value="'1'" :label="`全部`"></vxe-option>
                        <vxe-option :value="'2'" :label="`已维护`"></vxe-option>
                        <vxe-option :value="'3'" :label="`未维护`"></vxe-option>
                      </vxe-select>
                    </template>
                  </vxe-toolbar>
                  <vxe-toolbar perfect>
                    <template #buttons>
                      <span class="margin-right-xs text-bold">关键字</span>
                      <vxe-input v-model="filterCondition.keyword" style="width: calc(100% - 55px)" clearable class="vxeInputSearch" placeholder="关键字查询"></vxe-input>
                    </template>
                  </vxe-toolbar>
                  <div class="tableBox-category">
                    <vxe-table ref="categoryTableRef" :loading="categoryTableLoading" :data="dictItems.filter((data) => !filterCondition.keyword || (filterCondition.keyword && (data.name&&data.name.includes(filterCondition.keyword))))" height="auto" class="mytable-scrollbar" :scroll-y="{ enabled: true }" :row-config="{ isCurrent: true, isHover: true }" show-overflow @cell-click="tableCellClickCategory">
                      <vxe-column type="seq" width="30"></vxe-column>
                      <vxe-column field="name" title="类别明细"></vxe-column>
                    </vxe-table>
                  </div>
                </Pane>
                <Pane size="60">
                  <vxe-toolbar class="bg-olive light solid line-bottom text-orange" class-name="bg-olive light solid line-bottom text-orange">
                    <template #buttons>
                      <span class="margin-right-xs text-bold margin-left-xs">所属类别细菌</span>
                    </template>
                  </vxe-toolbar>
                  <vxe-toolbar perfect>
                    <template #buttons>
                      <span class="margin-right-xs text-bold">关键字</span>
                      <vxe-input v-model="filterCondition.germKeyword" style="width: calc(100% - 55px)" clearable class="vxeInputSearch" placeholder="关键字查询"></vxe-input>
                    </template>
                  </vxe-toolbar>
                  <div class="tableBox-germ">
                    <vxe-table ref="germaTableRef" :loading="germaTableLoading" :data="germDictItems.filter((data) => !filterCondition.germKeyword || (filterCondition.germKeyword && ((data.germNa&&data.germNa.includes(filterCondition.germKeyword)) || (data.germNo&&data.germNo.includes(filterCondition.germKeyword) )||(data.standardNa&& data.standardNa.includes(filterCondition.germKeyword)))))" height="auto" class="mytable-scrollbar" :scroll-y="{ enabled: true }" :row-config="{ isCurrent: true, isHover: true }" show-overflow>
                      <vxe-column type="seq" width="30"></vxe-column>
                      <vxe-column field="germNo" title="细菌编号"></vxe-column>
                      <vxe-column field="germNa" title="细菌名称"></vxe-column>
                      <vxe-column field="standardNa" title="标准名称"></vxe-column>
                    </vxe-table>
                  </div>
                </Pane>
              </Splitpanes>
            </el-main>
          </el-container>
        </Pane>
        <Pane size="50">
          <vxe-toolbar perfect class="bg-olive light solid line-bottom text-orange">
            <template #buttons>
              <vxe-input v-model="filterCondition.bpkeyvalue" clearable class="vxeInputSearch" placeholder="关键字查询"></vxe-input>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="showLoading" @click="findBreakPointListByCode({row:curSelectCategoryValue})"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="保存" :loading="saveShowLoading" @click="saveList"></vxe-button>
              <vxe-button type="text" class="button-red" icon="vxe-icon-delete" content="删除" @click="deleteBacBreakPoint"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="复制" @click="copyBreakPoint"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="粘贴" @click="pasteBreakPoint" :disabled="copyBreakPointList.length<=0"></vxe-button>
            </template>
            <template #tools>
              <span class="margin-right-xs text-bold margin-left-xs">自定义折点</span>
            </template>
          </vxe-toolbar>
          <div class="tableBox-breakpoint">
            <vxe-table ref="tableRef" border="inner" align="left" :loading="tableLoading" class="mytable-scrollbar" :scroll-y="{ enabled: true }" height="95%" :data="tableData.filter((data) => !filterCondition.bpkeyvalue || (filterCondition.bpkeyvalue && ((data.testMethod&&data.testMethod.includes(filterCondition.bpkeyvalue)) || (data.whonetOrgCode&&data.whonetOrgCode.includes(filterCondition.bpkeyvalue)) || (data.whonetAbxCode&&data.whonetAbxCode.includes(filterCondition.bpkeyvalue)) || (data.anaerobe&&data.anaerobe.includes(filterCondition.bpkeyvalue))|| (data.antName&&data.antName.includes(filterCondition.bpkeyvalue))|| (data.whonetAbxCode&&data.whonetAbxCode.includes(filterCondition.bpkeyvalue)) )))" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, enabled: true }" @cell-click="tableCellClick" show-overflow keep-source>
              <vxe-column type="checkbox" width="26"></vxe-column>
              <vxe-column type="seq" title="#" width="30"></vxe-column>
              <vxe-column field="whonetAbxCode" title="WHONET抗生素代码" width="150">
                <template #edit="{ row }">
                  <vxe-input v-model="row.whonetAbxCode" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="antName" title="WHONET抗生素名称" width="150">
                <template #edit="{ row }">
                  <vxe-input v-model="row.antName" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="guidelines" title="指南名称" width="80" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default>
                  <span>{{ `自定义` }}</span>
                </template>
                <template #edit>
                  <span>{{ `自定义` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="year" title="年份" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.year" clearable placeholder="年份" type="year" :value-format="'yyyy'"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="testMethod" title="测试方法" width="120" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row, rowIndex }">
                  <!-- <vxe-input v-model="row.testMethod" clearable placeholder="测试方法"></vxe-input> -->
                  <VxePulldownSelectionWithNa style="width: 100%" :isChild="true" :childIndex="rowIndex" :url="'/lis/bac/base/ast-test-mth/dict/findBacAstTestMthDictList'" @confirmClick="SelectRowClick" :tableColumn="[
                      { type: 'seq', title: '#', width: '30px' },
                      { field: 'name', title: '名称' },
                      { field: 'code', title: '编码', width: '60' }
                    ]" :aimKeys="[{ aimKey: 'testMethod', rowKey: 'code' }]" :displayTexts="['code']" :displayTextObj="row.testMethod ? row.testMethod : ''" />
                  <!-- <VxeDictSelection v-enterNextInput :isChild="false" :tableColumn="[{ field: 'code', title: '编码', width: `60px` },{ field: 'name', title: '名称', minWidth: `80px` }]" :url="`/api/sys/basDictDetail/findDictDetailList`" :displayTextObj="row.testMethod" @confirmClick="dropSelectConfirm" :aimKeys="[{ targetField: 'code', sourceField: 'code' }]" :dataObj="{ code: '' }"></VxeDictSelection> -->
                </template>
              </vxe-column>
              <vxe-column field="ref" title="折点" width="120" class-name="preserve-format" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span class="preserve-format">{{ `${row.ref}` }}</span>
                </template>
                <template #edit="{ row }">
                  <vxe-input v-model="row.ref" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="potency" title="效价" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.potency" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="r" title="耐药" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.r" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="i" title="中介" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.i" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="sdd" title="SDD" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.sdd" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="s" title="敏感" width="60" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.s" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="ecvEcoff" title="流行病学临界值" width="150" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <vxe-input v-model="row.ecvEcoff" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="serovarGroup" title="血清型" width="90" :edit-render="{}">
                <template #default="{ row }">
                  <span>{{ `${row.serovarGroup ? row.serovarGroup : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.serovarGroup ? row.serovarGroup : ''}` }}</span>
                  <!-- <vxe-input v-model="row.serovarGroup" type="text"></vxe-input> -->
                  <!-- <VxeDictSelection :isChild="true" :childIndex="rowIndex" :tableColumn="[{ field: 'code', title: '编码', width: `60px` },{ field: 'name', title: '名称', minWidth: `80px` }]" :url="`/api/sys/basDictDetail/findDictDetailList`" :displayTextObj="row.serovarGroup" @confirmClick="dropSelectConfirm" :aimKeys="[{ targetField: 'serovarGroup', sourceField: 'code' }]" :dataObj="{ code: 'serumGroup' }"></VxeDictSelection> -->
                </template>
              </vxe-column>
              <vxe-column field="whonetOrgCode" title="细菌代码" width="110" :edit-render="{}">
                <template #default="{ row }">
                  <span>{{ `${row.whonetOrgCode ? row.whonetOrgCode : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.whonetOrgCode ? row.whonetOrgCode : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="speciesGroup" title="种" width="70" :edit-render="{}">
                <template #default="{ row }">
                  <span>{{ `${row.speciesGroup ? row.speciesGroup : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.speciesGroup ? row.speciesGroup : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="genusCode" title="属" width="70" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span>{{ `${row.genusCode ? row.genusCode : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.genusCode ? row.genusCode : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="genusGroup" title="属分组" width="70" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span>{{ `${row.genusGroup ? row.genusGroup : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.genusGroup ? row.genusGroup : ''}` }}</span>
                </template>
              </vxe-column>

              <vxe-column field="familyCode" title="科" width="70" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span>{{ `${row.familyCode ? row.familyCode : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.familyCode ? row.familyCode : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="anaerobe" title="厌氧类型" width="100" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span>{{ `${row.anaerobe ? row.anaerobe : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.anaerobe ? row.anaerobe : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="subkingdomCode" title="亚界" width="100" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #default="{ row }">
                  <span>{{ `${row.subkingdomCode ? row.subkingdomCode : ''}` }}</span>
                </template>
                <template #edit="{ row }">
                  <span>{{ `${row.subkingdomCode ? row.subkingdomCode : ''}` }}</span>
                </template>
              </vxe-column>
              <vxe-column field="breakpointType" title="折点类型" width="100" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <!-- <vxe-input v-model="row.breakpointType" type="text"></vxe-input> -->
                  <vxe-select v-model="row.breakpointType" placeholder="折点类型">
                    <vxe-option :value="'Human'" :label="`Human`"></vxe-option>
                    <vxe-option :value="'Animal'" :label="`Animal`"></vxe-option>
                    <vxe-option :value="'ECOFF'" :label="`ECOFF`"></vxe-option>
                  </vxe-select>
                </template>
              </vxe-column>

              <vxe-column field="host" title="宿主" width="100" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row }">
                  <!-- <vxe-input v-model="row.host" type="text"></vxe-input> -->
                  <vxe-select v-model="row.host" placeholder="宿主">
                    <vxe-option :value="'Human'" :label="`Human`"></vxe-option>
                    <vxe-option :value="'Aquatic'" :label="`Aquatic`"></vxe-option>
                    <vxe-option :value="'Dogs'" :label="`Dogs`"></vxe-option>
                    <vxe-option :value="'Cattle'" :label="`Cattle`"></vxe-option>
                    <vxe-option :value="'Cats'" :label="`Cats`"></vxe-option>
                    <vxe-option :value="'Horses (adults)'" :label="`Horses (adults)`"></vxe-option>
                    <vxe-option :value="'Horses'" :label="`Horses`"></vxe-option>
                    <vxe-option :value="'Poultry'" :label="`Poultry`"></vxe-option>
                    <vxe-option :value="'Horses (foals)'" :label="`Horses (foals)`"></vxe-option>
                    <vxe-option :value="'Swine'" :label="`Swine`"></vxe-option>
                    <vxe-option :value="''" :label="`未知`"></vxe-option>
                  </vxe-select>
                </template>
              </vxe-column>
              <vxe-column field="siteOfInfection" title="感染部位" width="100" :edit-render="{ autofocus: '.vxe-input--inner' }">
                <template #edit="{ row, rowIndex }">
                  <!-- <vxe-input v-model="row.siteOfInfection" type="text"></vxe-input> -->
                  <VxePulldownSelectionWithNa style="width: 100%" :isChild="true" :childIndex="rowIndex" :url="'/lis/bac/base/site-of-infection/dict/findDictList'" @confirmClick="SelectRowClick" :tableColumn="[
                      { type: 'seq', title: '#', width: '30px' },
                      { field: 'name', title: '名称' },
                      { field: 'code', title: '编码', width: '60' }
                    ]" :aimKeys="[{ aimKey: 'siteOfInfection', rowKey: 'code' }]" :displayTexts="['code']" :displayTextObj="row.siteOfInfection ? row.siteOfInfection : ''" />
                </template>
              </vxe-column>

              <vxe-column field="dateEntered" title="折点信息的录入日期" width="150">
                <template #edit="{ row }">
                  <vxe-input v-model="row.dateEntered" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="dateModified" title="折点信息的修改日期" width="150">
                <template #edit="{ row }">
                  <vxe-input v-model="row.dateModified" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="comments" title="折点注释信息" min-width="150">
                <template #edit="{ row }">
                  <vxe-input v-model="row.comments" type="text"></vxe-input>
                </template>
              </vxe-column>
            </vxe-table>
          </div>
        </Pane>

        <Pane size="20">
          <vxe-toolbar perfect class="bg-olive light solid line-bottom text-orange">
            <template #buttons>
              <vxe-input v-model="form.keyvalue" clearable class="vxeInputSearch" placeholder="关键字查询" @keydown="keyEnter" @search-click="findList" @clear="findList"></vxe-input>
            </template>
            <template #tools>
              <span class="margin-right-xs text-bold margin-left-xs">抗生素</span>
            </template>
          </vxe-toolbar>
          <div class="tableBox">
            <vxe-table :data="antDictList.filter((data) => !form.keyvalue || (form.keyvalue && (data.antCode&&data.antCode.includes(form.keyvalue))||(data.antName&&data.antName.includes(form.keyvalue))))" class="mytable-scrollbar" height="auto" :scroll-y="{ enabled: true }" :loading="showLoading" :row-config="{ isCurrent: true, isHover: true }" @cell-dblclick="antCellDbClick">
              <!-- <vxe-column type="checkbox" width="30"></vxe-column> -->
              <vxe-column type="seq" width="60"></vxe-column>
              <vxe-column field="antCode" title="抗生素编号" width="80px"></vxe-column>
              <vxe-column field="antName" title="抗生素名称" width="180px"></vxe-column>
              <vxe-column field="whoCode" title="标准名称" width="140px"></vxe-column>
            </vxe-table>
          </div>
          <!-- <el-pagination :page-sizes="[10, 20, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="page.totalResult" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> -->
        </Pane>
      </Splitpanes>
    </div>
  </div>
</template>

<script lang="ts" setup>
// 引入组件区 ==========src\views\lab_sys\bac_set\BacGermDict.vue
import Breadcrumb from '../../../components/Breadcrumb.vue'; //面包屑
import { reactive, ref, getCurrentInstance, onMounted } from 'vue';
import { Splitpanes, Pane } from 'splitpanes';
import { VXETable } from 'vxe-table';
import { VxeMessage, VxeNotifyType } from '../../../utils/CommonMessage';
import type { VxeTableInstance, VxeTablePropTypes, VxeTableEvents } from 'vxe-table';
import BacBreakPointForm from './BacBreakPointForm.vue'; //基本信息表单组件
import ExtraPropertyPanel from '@/components/ExtraPropertyPanel.vue';
import { formatDateTime, IsEmpty } from '@/utils/common';
import VxeDictSelection from '@/components/VxeDictSelection.vue';
import VxePulldownSelectionWithNa from '@/components/VxePulldownSelectionWithNa.vue';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();

// 左侧表格:
let showLoading = ref(false); //刷新+表格加载
let sloading = ref(false);
const form = reactive({ keyvalue: '' }); //根据关键字查询
const tableRef = ref<VxeTableInstance<RowVO>>(); //表格ref标记
let tableLoading = ref(false);/* 自定义这点表格加载中 */
const tableData = reactive([]); //表格数据
const curSlectRow = ref({});
const categoryTableRef = ref(null);/* 分类明细表格对象 */
let categoryTableLoading = ref(false);/* 分类明细表格加载中 */

const germaTableRef = ref(null);/* 分类明细表格对象 */
let germaTableLoading = ref(false);/* 分类明细表格加载中 */

// 右侧表单:
const bacBreakPointFormRef = ref<InstanceType<typeof bacBreakPointFormRef>>(); //基本信息表单标记ref
let currentRow: any = reactive({ id: '', code: '' }); //基本信息表单当前行数据
const EditExtraPropertiesRef = ref(null); //配置扩展属性弹框ref
/* 筛选条件 */
let filterCondition = reactive({ value: 1, keyword: '', germKeyword: '', bpkeyvalue: '' });
// 分页
let page = reactive({
  currentPage: 1,
  pageSize: 100000,
  totalResult: 0
});
let curSelectCategory = ref('');
let curSelectCategoryValue = reactive({});
let saveShowLoading = ref(false);
/* 分组类别 */
let groupCategory = reactive([
  /*  { label: '血清型', value: 'serumGroup', isactive: true },
    { label: '细菌', value: 'WHONETORGCODE', isactive: false },
    { label: '种分组', value: 'speciesGroup', isactive: false },
    { label: '属', value: 'genusCode', isactive: false },
    { label: '属分组', value: 'genusGroup', isactive: false },
    { label: '科', value: 'familyCode', isactive: false },
    { label: '厌氧', value: 'ANAEROBE', isactive: false },
    { label: '亚界', value: 'SubkingdomCode', isactive: false }*/
]);

let dictItems = reactive([]); /* 各分类字典集合 */
let germDictItems = reactive([]); /* 细菌集合 */
let antDictList = reactive([]); /* 杭生素 列表 */
// 方法定义区 =============
onMounted(() => {
  getDictItemsList(); //获取检验组option下拉数据
  curSelectCategory.value = 'serumGroup';
  dictItems.length = 0;
  germDictItems.length = 0;
  tableData.length = 0;
  proxy.$nextTick(() => {
    setTimeout(async () => {
      changeGroupCategory(curSelectCategory.value);
      findList(); // 获取折点字典数据
    }, 500);
  });


});

//批量获取字典
async function getDictItemsList() {
  let dictTreeTypeCodes: any = ['groupCategory'];

  const codes = dictTreeTypeCodes.join(',');
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: codes } });
  const JYGZZType = dictTreeTypeItems.data.find((item) => item.code === 'groupCategory');
  groupCategory.push(...JYGZZType.detailDataList);
  console.log('groupCategory', groupCategory)
}

function getIsStaticStatusDesc(row) {
  if (row.isCommon) {
    return '是';
  } else {
    return '否';
  }
}

function getIsStaticTagType(row: any) {
  if (row.isCommon) {
    return 'success';
  } else {
    return 'danger';
  }
}

function getIsStaticStatusDesc1(row) {
  if (row.isAnaerobe) {
    return '是';
  } else {
    return '否';
  }
}
function getIsStaticTagType1(row) {
  if (row.isAnaerobe) {
    return 'success';
  } else {
    return 'danger';
  }
}

function keyEnter(e: any) {
  if (e.$event.code == 'Enter') {
    findList();
  }
}

// 获取折点
const findList = () => {
  showLoading.value = true;
  antDictList.length = 0; //放入数据前清空数据
  const url = '/lis/bacAntibioticsDict/findAntibioticsDictPageList';
  proxy.$http
    //注意此处的数据条数
    .get(url, { params: { searchValue: form.keyvalue, pageIndex: page.currentPage, pageSize: page.pageSize } })
    .then(async (res: any) => {
      page.totalResult = res.data.total;
      Object.assign(antDictList, res.data.records);
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('获取折点数据异常', VxeNotifyType.error);
    });
};

// 新增折点
function addBacBreakPoint() {
  const $formRef = bacBreakPointFormRef.value;
  bacBreakPointFormRef.value.addNew();
}

// 删除折点
function deleteBacBreakPoint() {
  const row = tableRef.value?.getCurrentRecord();
  const arr = [row];
  proxy
    .$confirm('确定要删除选中的数据？', '提示', {
      cancelButtonClass: 'cancel-button',
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    .then(() => {
      const data = { bacBreakPointList: arr };
      const url = '/bac-break-point/batchDeleteBreakPoint';
      proxy.$http
        .post(url, data)
        .then((res: any) => {
          VxeMessage(res.status.msg, VxeNotifyType.success);
          findBreakPointListByCode({ row: curSelectCategoryValue });
        })
        .catch((err: any) => {
          VxeMessage(err, VxeNotifyType.error);
        });
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 表格选中当前行
function tableCellClick({ row }: any) {
  curSlectRow.value = row;
  Object.assign(currentRow, row);
  proxy.$forceUpdate();
}

//更换一页显示数量
function handleSizeChange(val) {
  page.pageSize = val;
  findList();
}

// 点击下一页
function handleCurrentChange(val) {
  page.currentPage = val;
  findList();
}
/* 切换属分组 */
function changeGroupCategory(val) {
  groupCategory.forEach((item) => {
    item.isactive = 'false';
  });
  groupCategory.find((item) => item.value == val).isactive = 'true';
  findDictDataList(val);
}
/* 查询字典数据 */
function findDictDataList(keyCode) {
  curSelectCategory.value = keyCode;
  germDictItems.length = 0;
  tableData.length = 0;
  switch (keyCode) {
    case 'serumGroup':
      findDictDataListAction('serumGroup');
      break;
      break;
    case 'familyCode':
      findDictDataListAction('familyCode');
      break;
      break;
    case 'genusGroup':
      findDictDataListAction('genusGroup');
      break;
      break;
    case 'genusCode':
      findDictDataListAction('genusCode');
      break;
    case 'speciesGroup':
      findDictDataListAction('speciesGroup');
      break;
    case 'SubkingdomCode':
      findDictDataListAction('SubkingdomCode');
      break;
    case 'WHONETORGCODE':
      findDictDataListAction('WHONETORGCODE');
      break;
    case 'ANAEROBE':
      findDictDataListAction('ANAEROBE');
      break;
    default:
      break;
  }
}
/* 执行查询 */
function findDictDataListAction(key) {
  categoryTableLoading.value = true;
  dictItems.length = 0;
  const url = '/bac-break-point/findCategoryByCode';
  proxy.$http.get(url, { params: { cateGoryCode: key, filterCondition: filterCondition.value, keyword: IsEmpty(filterCondition.keyword) ? '' : filterCondition.keyword } }).then((res: any) => {
    Object.assign(dictItems, res.data);
    categoryTableRef.value?.setCurrentRow(dictItems[0]);
    findGermDictListByCode({ row: dictItems[0] });
    findBreakPointListByCode({ row: dictItems[0] });
    categoryTableLoading.value = false;
  });
}
/* 分类明细行点击事件 */
function tableCellClickCategory({ row }) {
  Object.assign(curSelectCategoryValue, row);
  findGermDictListByCode({ row });
  findBreakPointListByCode({ row });
}
/* 查询细菌 */
function findGermDictListByCode({ row }) {
  germaTableLoading.value = true;
  germDictItems.length = 0;
  const url = '/bac-break-point/findGermDictListByCode';
  proxy.$http.post(url, { cateGoryCode: curSelectCategory.value, filterCondition: filterCondition.value, keyword: filterCondition.germKeyword, breakPointMapperCategoryDto: row }).then((res: any) => {
    Object.assign(germDictItems, res.data);
    germaTableRef.value?.setCurrentRow(germDictItems[0]);
    germaTableLoading.value = false;
  });
}
/* 查询折点 */
function findBreakPointListByCode({ row }) {
  tableLoading.value = true;
  tableData.length = 0;
  const url = '/bac-break-point/findBreakPointListByCode';
  proxy.$http.post(url, { cateGoryCode: curSelectCategory.value, filterCondition: filterCondition.value, keyword: filterCondition.germKeyword, breakPointMapperCategoryDto: row }).then((res: any) => {
    Object.assign(tableData, res.data);
    tableRef.value?.setCurrentRow(tableData[0]);
    tableLoading.value = false;
  });
}
/* 抗生素双击事件 */
function antCellDbClick({ row }) {
  let newRow = {
    anaerobe: null,
    breakpointType: 'Human',
    comments: null,
    dateEntered: formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss'),
    dateModified: null,
    delFlag: 0,
    ecvEcoff: null,
    ecvEcoffTentative: false,
    familyCode: null,
    genusCode: '',
    genusGroup: '',
    guidelines: 'AUser-defined',
    host: 'Human',
    i: '',
    id: '',
    organismCode: null,
    potency: '',
    r: '',
    ref: '',
    referenceTable: '',
    s: '',
    sdd: null,
    serovarGroup: null,
    siteOfInfection: null,
    speciesGroup: null,
    subkingdomCode: null,
    testMethod: '',
    whonetAbxCode: row.antCode,
    antName: row.antName,
    whonetOrgCode: null,
    whonetTest: '',
    year: parseInt(formatDateTime(new Date(), 'yyyy'))
  };
  switch (curSelectCategory.value) {
    case 'serumGroup':
      newRow.serovarGroup = curSelectCategoryValue.code;
      break;
    case 'familyCode':
      newRow.familyCode = curSelectCategoryValue.code;
      break;
    case 'genusGroup':
      newRow.genusGroup = curSelectCategoryValue.code;
      break;
    case 'genusCode':
      newRow.genusCode = curSelectCategoryValue.code;
      break;
    case 'speciesGroup':
      newRow.speciesGroup = curSelectCategoryValue.code;
      break;
    case 'SubkingdomCode':
      newRow.subkingdomCode = curSelectCategoryValue.code;
      break;
    case 'WHONETORGCODE':
      newRow.whonetOrgCode = curSelectCategoryValue.code;
      break;
    case 'ANAEROBE':
      newRow.anaerobe = !IsEmpty(curSelectCategoryValue.code) ? 'ANA' : null;
      break;
    default:
      break;
  }
  tableData.unshift(newRow);
}
/* 下拉选择选中事件 */
function SelectRowClick(e) {
  if (e.isChild) {
    e.aimKeys.forEach((item) => {
      tableData[e.childIndex][item.aimKey] = e.row[item.rowKey];
    });
  }
}
/* 字典数据下拉选中事件 */
function dropSelectConfirm(e) {
  console.log('字典数据下拉选中事件', e);
}
/* 保存折点 */
function saveList() {
  saveShowLoading.value = true;
  tableData.forEach((item, idx) => {
    let url = '';
    // 判断添加和编辑接口
    if (IsEmpty(item.id)) {
      url = '/bac-break-point/addBreakPoint';
    } else {
      url = '/bac-break-point/updateBreakPoint';
    }
    proxy.$http
      .post(url, item)
      .then((res: any) => {
        if (idx === tableData.length - 1) {
          saveShowLoading.value = false;
          VxeMessage('操作成功', VxeNotifyType.success);
          findBreakPointListByCode({ row: curSelectCategoryValue });
        }
      })
      .catch((err: any) => {
        if (idx === tableData.length - 1) {
          saveShowLoading.value = false;
        }
        VxeMessage(`第${idx + 1}条处理失败`, VxeNotifyType.error);
      });
  });
}

let copyBreakPointList: any = reactive([]);

function copyBreakPoint() {
  const rowList = (proxy.$refs.tableRef as any).getCheckboxRecords();
  if (rowList.length > 0) {
    copyBreakPointList.length = 0;
    VxeMessage('已复制到剪贴板', VxeNotifyType.success);
    copyBreakPointList.push(...rowList);
  } else {
    VxeMessage('没有要复制的数据', VxeNotifyType.error);
  }
}
function pasteBreakPoint() {
  for (let copyDict of copyBreakPointList) {
    let record: any = {
      whonetAbxCode: copyDict.whonetAbxCode,
      antName: copyDict.antName,
      guidelines: copyDict.guidelines,
      year: copyDict.year,
      testMethod: copyDict.testMethod,
      ref: copyDict.ref,
      potency: copyDict.potency,
      r: copyDict.r,
      i: copyDict.i,
      sdd: copyDict.sdd,
      s: copyDict.s,
      ecvEcoff: copyDict.ecvEcoff,
      serovarGroup: null,
      whonetOrgCode: null,
      speciesGroup: null,
      genusCode: '',
      genusGroup: '',
      familyCode: null,
      anaerobe: null,
      subkingdomCode: null,
      breakpointType: copyDict.breakpointType,
      host: copyDict.host,
      siteOfInfection: copyDict.siteOfInfection,
      dateEntered: formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss'),
      dateModified: copyDict.dateModified,
      comments: copyDict.comments
    };
    switch (curSelectCategory.value) {
      case 'serumGroup':
        record.serovarGroup = curSelectCategoryValue.code;
        break;
      case 'familyCode':
        record.familyCode = curSelectCategoryValue.code;
        break;
      case 'genusGroup':
        record.genusGroup = curSelectCategoryValue.code;
        break;
      case 'genusCode':
        record.genusCode = curSelectCategoryValue.code;
        break;
      case 'speciesGroup':
        record.speciesGroup = curSelectCategoryValue.code;
        break;
      case 'SubkingdomCode':
        record.subkingdomCode = curSelectCategoryValue.code;
        break;
      case 'WHONETORGCODE':
        record.whonetOrgCode = curSelectCategoryValue.code;
        break;
      case 'ANAEROBE':
        record.anaerobe = !IsEmpty(curSelectCategoryValue.code) ? 'ANA' : null;
        break;
      default:
        break;
    }

    tableData.push(record);

  }
}
</script>
<style lang="scss" scoped>
#bacBreakPoint {
  width: 100%;
  height: 100%;

  .bodyContent {
    // 面包屑40px  上下间距10px
    height: calc(100% - 60px);

    .area {
      background-color: $base-white;

      // 附加按钮间距
      .button-blue,
      .button-red {
        margin: 5px 0 5px 5px;
      }

      .tableBox-breakpoint {
        height: calc(100%);
      }
      .tableBox-germ {
        height: calc(100% - 30px - 30px);
      }
      .tableBox-category {
        height: calc(100% - 30px - 30px - 30px);
      }
      .tableBox {
        height: calc(100% - 30px);
      }

      .el-tabs--border-card {
        border: none;
        height: 100%;

        :deep(.el-tabs__content) {
          height: calc(100% - 39px - 30px);

          .el-tab-pane {
            height: 100%;
          }
        }
      }
    }
  }
}

.preserve-format {
  white-space: pre-wrap; /* 保留空格和换行，并支持自动换行 */
  font-family: monospace; /* 可选：使用等宽字体 */
}
</style>
